package com.talkweb.newproject.admin.controller;

import com.talkweb.newproject.admin.rest.SysPositionRest;
import com.talkweb.newproject.admin.sysposition.dto.SysPositionDTO;
import com.talkweb.newproject.admin.sysposition.service.SysPositionService;
import com.talkweb.newproject.api.model.admin.SysPositionParam;
import com.talkweb.newproject.api.model.common.ResponseResult;
import com.talkweb.newproject.api.model.common.Status;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by qsf on 2019/5/13.
 */
@RestController
@RequestMapping(value="/api/sysPosition")
@Slf4j
public class SysPositionController {
    @Autowired
    private SysPositionRest sysPositionRest;

    /**
     * 根据id获取position对象
     * @param ID
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/Web/get/v1/{ID}")
    public ResponseResult<SysPositionDTO> querySysPositionByPrimaryKey(@RequestParam("ID") String ID) throws Exception {
        ResponseResult<SysPositionDTO> result = new ResponseResult<>();
        try{

            return sysPositionRest.querySysPositionByPrimaryKey(ID);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }

    }

    /**
     * 查询列表时
     * @param obj
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/Web/getSysPositionList",method = RequestMethod.POST)
    public Object querySysPositionList(@RequestBody SysPositionParam obj) throws Exception {
        Object result = new ResponseResult<>();
        try{

            result = sysPositionRest.querySysPositionList(obj);
            return result;
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            return result;
        }
    }

    /**
     * 根据条件查询单个对象
     * @param obj
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/Web/queryLike",method = RequestMethod.POST)
    public ResponseResult<SysPositionDTO> queryLike(@RequestBody SysPositionDTO obj) throws Exception{
        ResponseResult<SysPositionDTO> result=new ResponseResult<>();
        try{

            return sysPositionRest.queryLike(obj);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }

    }

    /**
     * 新增数据
     * @param obj
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/Web/create/v1",method = RequestMethod.POST)
    public ResponseResult insertSysPostion(@RequestBody SysPositionDTO obj) throws Exception {
        ResponseResult result = new ResponseResult();
        try{
            return sysPositionRest.create(obj);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }

    }

    /**
     * 更新数据
     * @param obj
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/Web/update/v1",method = RequestMethod.POST)
    public ResponseResult updateSysPosition(@RequestBody SysPositionDTO obj) throws Exception {
        ResponseResult result = new ResponseResult();
        try{

            return sysPositionRest.update(obj);
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }

    }

    /**
     * 根据id删除数据
     * @param ids
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/deleteSysPositionById",method = RequestMethod.POST)
    public ResponseResult<Object> deleteSysPositionById2(@RequestParam("ids") String ids) throws Exception {
        ResponseResult<Object> result = new ResponseResult<>();
        try{
            if(ids != null && !"".equals(ids)){
                result = sysPositionRest.deleteSysPositionById(ids);
                result.setMessage("删除成功");
                result.setStatus(Status.SUCCESS);
            }else {
                result.setStatus(Status.FAILD);
                result.setMessage("删除失败");
            }
            return result;
        }catch(Exception e) {
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }


    }
}
